﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Drawing.Printing;
using System.Data.SqlClient;
using System.Net;


namespace BACKOFFICE
{
    public partial class Testing : DevExpress.XtraEditors.XtraForm
    {
        public static float x = 1;
        public static float y = 10;
        public static float width = 300.0F - 120f; // max width I found through trial and error
        public static float height = 0F;

        public static Font drawFontArial12Bold;
        public static Font drawFontArial10Regular;
        public static Font drawFontArial10Bold;
        public static Font drawFontArialRegular;
        public static Font drawFontArialBold;
        public static SolidBrush drawBrush;

        // Set format of string.
        public static StringFormat drawFormatCenter = new StringFormat();
        public static StringFormat drawFormatLeft = new StringFormat();
        public static StringFormat drawFormatRight = new StringFormat();

        string myConnectionString = "Data Source=" + "192.168.1.13" + "," + "1433" + ";Network Library=DBMSSOCN;Initial Catalog=RabbitPosSoftware;User ID=sa;Password=502370;";
        public static DataTable EmployeeLogin = new DataTable("EmployeeLogin");
        public static DataTable EmployeeSchedule = new DataTable("EmployeeSchedule");

        static int EmpID;

        public Testing()
        {
            InitializeComponent();

            drawFormatCenter.Alignment = StringAlignment.Center;
            drawFormatLeft.Alignment = StringAlignment.Near;
            drawFormatRight.Alignment = StringAlignment.Far;

            drawFontArial12Bold = new Font("Courier New", 12, FontStyle.Bold);
            drawFontArial10Regular = new Font("Courier New", 9, FontStyle.Regular);
            drawBrush = new SolidBrush(Color.Black);
        }

        public void LoadDataTable(string Table, DataTable DataTable)
        {
            //SplashScreen1._main.labelControl2.Text = "LOADING " + Table.ToUpper() + " DATATABLE";
            SqlConnection conn = new SqlConnection(myConnectionString);
            conn.Open();

            string query = "SELECT * FROM " + Table;

            SqlCommand cmd = new SqlCommand(query, conn);
            using (SqlDataAdapter a = new SqlDataAdapter(cmd))
            {

                a.Fill(DataTable);
            }

            conn.Close();

        }

        private void Testing_Load(object sender, EventArgs e)
        {
            LoadDataTable("EmployeeLogin", EmployeeLogin);
            LoadDataTable("EmployeeSchedule", EmployeeSchedule);
            PrintSetup();
            PrintReceiptForTransaction();

            
            
        }

        public static void PrintSetup()
        {
            drawFormatCenter.Alignment = StringAlignment.Center;
            drawFormatLeft.Alignment = StringAlignment.Near;
            drawFormatRight.Alignment = StringAlignment.Far;

            drawFontArial12Bold = new Font("Microsoft Sans Serif", 7, FontStyle.Bold);
            drawFontArial10Regular = new Font("Microsoft Sans Serif", 6, FontStyle.Regular);
            drawFontArial10Bold = new Font("Microsoft Sans Serif", 8, FontStyle.Bold);
            drawFontArialRegular = new Font("Microsoft Sans Serif", 18, FontStyle.Regular);
            drawFontArialBold = new Font("Microsoft Sans Serif", 9, FontStyle.Bold);
            drawBrush = new SolidBrush(Color.Black);
        }

        public void PrintReceiptForTransaction()
        {
            EmpID = 6577;
            //PrintPreview();

            PrinterPrint();

        }

        void PrintPreview()
        {
            PrintDocument printDocument = new PrintDocument();

            printPreviewControl1.Document = printDocument;
            printPreviewControl1.Zoom = 1.5;
            printDocument.PrintPage += new PrintPageEventHandler(PrintReceiptPage);
        }

        void PrinterPrint()
        {
            PrintDialog printDialog = new PrintDialog();


            PrintDocument printDocument = new PrintDocument();

            printDialog.Document = printDocument;
            printDocument.PrintPage += new PrintPageEventHandler(PrintReceiptPage);




            DialogResult result = printDialog.ShowDialog();

            if (result == DialogResult.OK)
            {
                printDocument.Print();
            }

            printDocument.Dispose();
        }

        private static void PrintReceiptPage(object sender, PrintPageEventArgs e)
        {

            //PrintHeader(e);
            PrintCreditCardSlip(e);
            //PrintFooter(e);

            x = 2;
            y = 10;
            width = 300.0F - 120f; // max width I found through trial and error
            height = 0F;
        }

        static void PrintHeader(PrintPageEventArgs e)
        {
            // Draw string to screen.
            string text = "Hayashi Japanese Restaurant";
            e.Graphics.DrawString(text, drawFontArial12Bold, drawBrush, new RectangleF(x, y, width, height), drawFormatCenter);
            y += e.Graphics.MeasureString(text, drawFontArial12Bold).Height;

            text = "4220 82nd St.";
            e.Graphics.DrawString(text, drawFontArial10Regular, drawBrush, new RectangleF(x, y, width, height), drawFormatCenter);
            y += e.Graphics.MeasureString(text, drawFontArial10Regular).Height;

            text = "Lubbock, Tx 79423";
            e.Graphics.DrawString(text, drawFontArial10Regular, drawBrush, new RectangleF(x, y, width, height), drawFormatCenter);
            y += e.Graphics.MeasureString(text, drawFontArial10Regular).Height;

            text = "Phone (806)792-6868";
            e.Graphics.DrawString(text, drawFontArial10Regular, drawBrush, new RectangleF(x, y, width, height), drawFormatCenter);
            y += e.Graphics.MeasureString(text, drawFontArial10Regular).Height;

            text = "==================================";
            e.Graphics.DrawString(text, drawFontArial10Regular, drawBrush, new RectangleF(x, y, width, height), drawFormatCenter);
            y += e.Graphics.MeasureString(text, drawFontArial10Regular).Height;

        }

        static void PrintFooter(PrintPageEventArgs e)
        {
            string text = " ";
            e.Graphics.DrawString(text, drawFontArial12Bold, drawBrush, new RectangleF(x, y, width, height), drawFormatCenter);
            y += e.Graphics.MeasureString(text, drawFontArial12Bold).Height;
            text = " ";
            e.Graphics.DrawString(text, drawFontArial10Regular, drawBrush, new RectangleF(x, y, width, height), drawFormatCenter);
            y += e.Graphics.MeasureString(text, drawFontArial12Bold).Height;
            text = " ";
            e.Graphics.DrawString(text, drawFontArial12Bold, drawBrush, new RectangleF(x, y, width, height), drawFormatCenter);
            y += e.Graphics.MeasureString(text, drawFontArial12Bold).Height;
            // Draw string to screen.
            text = "Thank You For Your Business.\n For Comments Please Give Us A Call";
            e.Graphics.DrawString(text, drawFontArial12Bold, drawBrush, new RectangleF(x, y, width, height), drawFormatCenter);
            y += e.Graphics.MeasureString(text, drawFontArial12Bold).Height;

            //// Create pen.
            //Pen blackPen = new Pen(Color.Black, 1);
            //// Create rectangle.
            //Rectangle rect = new Rectangle(0, 0, (int)width-120, (int)y + 30);
            //// Draw rectangle to screen.
            //e.Graphics.DrawRectangle(blackPen, rect);

        }

        static void PrintCreditCardSlip(PrintPageEventArgs e)
        {
            string text;
            text = " ";
            e.Graphics.DrawString(text, drawFontArialRegular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
            y += e.Graphics.MeasureString(text, drawFontArialRegular).Height;

            text = " ";
            e.Graphics.DrawString(text, drawFontArialRegular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
            y += e.Graphics.MeasureString(text, drawFontArialRegular).Height;

            text = "火盆雞\n     沒有圍牆\n     雙炒飯";
            e.Graphics.DrawString(text, drawFontArialRegular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
            y += e.Graphics.MeasureString(text, drawFontArialRegular).Height;

            text = "hibachi chicken no veggi Double fried rice";
            e.Graphics.DrawString(text, drawFontArialBold, drawBrush, new RectangleF(x, y, width, height), drawFormatCenter);
            y += e.Graphics.MeasureString(text, drawFontArialBold).Height;

            text = " ";
            e.Graphics.DrawString(text, drawFontArialRegular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
            y += e.Graphics.MeasureString(text, drawFontArialRegular).Height;

            text = " ";
            e.Graphics.DrawString(text, drawFontArialRegular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
            y += e.Graphics.MeasureString(text, drawFontArialRegular).Height;

            //text = " ";
            //e.Graphics.DrawString(text, drawFontArialRegular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
            //y += e.Graphics.MeasureString(text, drawFontArialRegular).Height;

            //text = "VISA";
            //e.Graphics.DrawString(text, drawFontArialRegular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
            //y += e.Graphics.MeasureString(text, drawFontArialRegular).Height;

            //text = "" + "XXXXXXXXXXXX9013";
            //e.Graphics.DrawString(text, drawFontArialRegular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
            //y += e.Graphics.MeasureString(text, drawFontArialRegular).Height;

            //text = "Entry Method: " + "Swiped";
            //e.Graphics.DrawString(text, drawFontArialRegular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
            //y += e.Graphics.MeasureString(text, drawFontArialRegular).Height;

            //text = "Invoice #:" + "42070100";
            //e.Graphics.DrawString(text, drawFontArialRegular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
            //y += e.Graphics.MeasureString(text, drawFontArialRegular).Height;

            //text = "Appr Code: " + "ZYUYL";
            //e.Graphics.DrawString(text, drawFontArialRegular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
            //y += e.Graphics.MeasureString(text, drawFontArialRegular).Height;

            //text = " ";
            //e.Graphics.DrawString(text, drawFontArialRegular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
            //y += e.Graphics.MeasureString(text, drawFontArialRegular).Height;

            //text = " ";
            //e.Graphics.DrawString(text, drawFontArialRegular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
            //y += e.Graphics.MeasureString(text, drawFontArialRegular).Height;

            //text = "Amount:".PadRight(15) + "$287.93";
            //e.Graphics.DrawString(text, drawFontArialRegular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
            //y += e.Graphics.MeasureString(text, drawFontArialRegular).Height;

            //text = " ";
            //e.Graphics.DrawString(text, drawFontArialRegular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
            //y += e.Graphics.MeasureString(text, drawFontArialRegular).Height;

            //text = "TIP:".PadRight(12) + "__________";
            //e.Graphics.DrawString(text, drawFontArialRegular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
            //y += e.Graphics.MeasureString(text, drawFontArialRegular).Height;

            //text = " ";
            //e.Graphics.DrawString(text, drawFontArialRegular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
            //y += e.Graphics.MeasureString(text, drawFontArialRegular).Height;

            //text = "Total:".PadRight(12) + "__________";
            //e.Graphics.DrawString(text, drawFontArialRegular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
            //y += e.Graphics.MeasureString(text, drawFontArialRegular).Height;

            //text = " ";
            //e.Graphics.DrawString(text, drawFontArialRegular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
            //y += e.Graphics.MeasureString(text, drawFontArialRegular).Height;

            //text = " ";
            //e.Graphics.DrawString(text, drawFontArialRegular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
            //y += e.Graphics.MeasureString(text, drawFontArialRegular).Height;

            //text = " ";
            //e.Graphics.DrawString(text, drawFontArialRegular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
            //y += e.Graphics.MeasureString(text, drawFontArialRegular).Height;

            //text = "Thank You!";
            //e.Graphics.DrawString(text, drawFontArialRegular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft);
            //y += e.Graphics.MeasureString(text, drawFontArialRegular).Height;

        }
    }
}